package compute;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Practice3 extends JFrame implements ActionListener{
	private JButton an1,an2;
	private JPanel mb;
	private Jtz jtz;
public Practice3(){
	jtz=new Jtz();
	mb=new JPanel();
	an1=new JButton("红色");
	an1.addActionListener(this);
	an1.addActionListener(jtz);
	an1.setActionCommand("1");
	an2=new JButton("蓝色");
	an2.addActionListener(this);
	an2.addActionListener(jtz);
	an2.setActionCommand("2");
	mb.setBackground(Color.blue);
	add(an1,BorderLayout.SOUTH);add(an2,BorderLayout.NORTH);
	add(mb);
	setSize(500, 500);
	setLocation(100, 100);
	setDefaultCloseOperation(EXIT_ON_CLOSE);
	setVisible(true);
}
class ht extends JPanel{
	public void paint(Graphics g){
		super.paint(g);
	}
}
public static void main(String[] args) {
	Practice3 a=new Practice3();
}
@Override
public void actionPerformed(ActionEvent e) {
	if(e.getActionCommand().equals("1"))
	{
		
	}
	if(e.getActionCommand().equals("2")){
		System.out.println("按的是蓝色按钮");
	}	
}
}
class Jtz implements ActionListener{

	@Override
	public void actionPerformed(ActionEvent a) {
	if(a.getActionCommand().equals("1"))
	{
		System.out.println("按的是红色按钮");
	}
	if(a.getActionCommand().equals("2")){
		System.out.println("按的是蓝色按钮");
	}	
	}
	
}
